﻿using DataAccessObject;
using DataAccessObject.DAO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BUSINESS
{
    public class GiaoVienBUS
    {
        static GiaoVienDAO dao = new GiaoVienDAO();
        
        /// <summary>
        /// 
        /// </summary>
        /// <param name="giaovien"></param>
        /// <returns></returns>
        public static string InsertGiaoVien(GIAOVIEN giaovien)
        {
            string result = string.Empty;
            result = checkValidData(giaovien);
            if (result == string.Empty) 
                dao.insertGiaoVien(giaovien);
            return result;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static List<GIAOVIEN> getAllGiaoVien()
        {
            return dao.getAllGiaoVien();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="giaovien"></param>
        /// <returns></returns>
        public static string checkValidData(GIAOVIEN giaovien)
        {
            string result = string.Empty;
            var _giaovien = dao.getByMaGiaoVien(giaovien.MaGiaoVien);
            if (_giaovien.Count() > 0)
            {
                result += "*Mã Giáo viên đã tồn tại\n";
            }
            _giaovien = dao.getGiaoVienByCMND(giaovien.CMND);
            if (_giaovien.Count() > 0) 
            {
                result += "*Chứng minh nhân dân đã tồn tại\n";
            }
            return result;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="giaovien"></param>
        public static string updateGiaoVien(GIAOVIEN giaovien)
        {
            string result = string.Empty;
            var giaoviens = dao.getByMaGiaoVienById(giaovien.MaGiaoVien, giaovien.UserId);
            if (giaoviens.Count() > 0) result += "*Mã giáo viên thay đổi đã tồn tại\n";
            giaoviens = dao.getGiaoVienByCMND(giaovien.CMND, giaovien.UserId);
            if (giaoviens.Count() > 0) result += "*CMND thay đổi đã tồn tại\n";
            dao.updateGiaoVien(giaovien);
            return result;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="giaovien"></param>
        public static void deleteGiaoVien(GIAOVIEN giaovien)
        {
            dao.deleteGiaoVien(giaovien);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="giaovien"></param>
        /// <param name="khoilop"></param>
        /// <param name="monhoc"></param>
        public static void updateGiaoVienChuyenMon(GIAOVIEN giaovien, KHOILOP khoilop, MONHOC monhoc)
        {
            dao.updateGiaoVienChuyenMon(giaovien, khoilop, monhoc);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="giaovien"></param>
        /// <returns></returns>
        public static List<CHITIETMONHOC> getChuyenMonByGiaoVien(GIAOVIEN giaovien)
        {
            return dao.getChuyenMonByGiaoVien(giaovien);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="chitietmonhoc"></param>
        public static void deleteGiaoVienChuyenMon(GIAOVIEN giaovien, CHITIETMONHOC chitietmonhoc)
        {
            dao.deleteGiaoVienChuyenMon(giaovien, chitietmonhoc);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="cHITIETMONHOC"></param>
        /// <returns></returns>
        public static List<GIAOVIEN> getGiaoVienByChuyenMon(CHITIETMONHOC cHITIETMONHOC)
        {
            return dao.getGiaoVienByChuyenMon(cHITIETMONHOC);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="namhoc"></param>
        /// <returns></returns>
        public static List<GIAOVIEN> getAllNoneChuNhiem(NAMHOC namhoc)
        {
            return dao.getAllNoneChuNhiem(namhoc);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        public static GIAOVIEN getGiaoVienById(int p)
        {
            return dao.getGiaoVienById(p);
        }
    }
}
